import { CrudOptions } from "@nestjsx/crud";
import { HandleStatus } from "libs/db/entity/enum/handle-status.enum";
import { VillageCadre } from "libs/db/entity/village-cadre.entity";
import { LoggerInfo, moduleLoggerInfo } from "../_decorator/logger-info";

export const VillageCadreCrudOps: CrudOptions = {
  model: {
    type: VillageCadre
  },
  query: {
     
    join: {
      group: {
          
        exclude:  ["updatedAt", "deleteAt"],
      },
      village: {
          
        exclude:  ["updatedAt", "deleteAt"],
      },
      "village.town": {
          
        exclude:  ["updatedAt", "deleteAt"],
      },
    },
    exclude:  ["updatedAt", "deleteAt"]
  },
  routes: {
    only: ['getOneBase', 'getManyBase'],
    exclude: ['createManyBase', 'createOneBase', 'deleteOneBase', 'replaceOneBase', 'updateOneBase'],
    getManyBase: {
      interceptors: [],
      decorators: [
        LoggerInfo(
          new moduleLoggerInfo ('村干部查询', HandleStatus.LOG)
        ),
      ],
    },
    getOneBase: {
      interceptors: [],
      decorators: [
        LoggerInfo(
          new moduleLoggerInfo ('单个村干部查询', HandleStatus.LOG)
        ),
      ],
    },
    createOneBase: {
      interceptors: [],
      decorators: [
        LoggerInfo(
          new moduleLoggerInfo ('新增村干部信息', HandleStatus.INFO)
        ),
      ],
      returnShallow: true,
    },
    createManyBase: {
      interceptors: [],
      decorators: [
        LoggerInfo(
          new moduleLoggerInfo ('村干部信息上传', HandleStatus.DATA)
        ),
      ],
    },
    replaceOneBase: {
      interceptors: [],
      decorators: [
        LoggerInfo(
          new moduleLoggerInfo ('修改村干部信息', HandleStatus.WARN)
        ),
      ],
      allowParamsOverride: true,
      returnShallow: true,
    },
    updateOneBase: {
      interceptors: [],
      decorators: [
        LoggerInfo(
          new moduleLoggerInfo ('修改村干部信息', HandleStatus.WARN)
        ),
      ],
      allowParamsOverride: true,
      returnShallow: true,
    },
    deleteOneBase: {
      interceptors: [],
      decorators: [
        LoggerInfo(
          new moduleLoggerInfo ('删除村干部信息', HandleStatus.ERROR)
        ),
      ],
      returnDeleted: true,
    },
  },
  dto: {
    create: VillageCadre,
    replace: VillageCadre
  },
  serialize: {
    getMany: VillageCadre,
    get: VillageCadre,
    create: VillageCadre,
    createMany: VillageCadre,
    update: VillageCadre,
    replace: VillageCadre,
    delete: VillageCadre,
  }
}